{% extends 'base.html' %}
{% load static %}

{% block title %}搜索结果 - {{ query }}{% endblock %}

{% block content %}
<div class="container py-5">
    <div class="row">
        <div class="col-12">
            <h2>搜索结果："{{ query }}"</h2>
            {% if products %}
                <div class="row mt-4">
                    {% for product in products %}
                        <div class="col-md-4 mb-4">
                            <div class="card h-100">
                                <img src="{{ product.image.url }}" class="card-img-top" alt="{{ product.title }}">
                                <div class="card-body">
                                    <h5 class="card-title">{{ product.title }}</h5>
                                    <p class="card-text">{{ product.description|truncatewords:20 }}</p>
                                    <a href="{% url 'product_detail' product.id %}" class="btn btn-primary">查看详情</a>
                                </div>
                            </div>
                        </div>
                    {% endfor %}
                </div>
            {% else %}
                <div class="alert alert-info">
                    没有找到与"{{ query }}"相关的结果。
                </div>
            {% endif %}
        </div>
    </div>
</div>
{% endblock %}
